import 'package:flutter_tts/flutter_tts.dart';

class TextToSpeechService {
  final FlutterTts flutterTts = FlutterTts();

  Future<void> init() async {
    await flutterTts.setLanguage("zh-CN"); // 设置中文
    await flutterTts.setSpeechRate(0.9);   // 语速
    await flutterTts.setVolume(1.0);       // 音量
    await flutterTts.setPitch(1.0);        // 音调
  }

  Future<void> speak(String text) async {
    if (text.isNotEmpty) {
      await flutterTts.speak(text);
    }
  }

  Future<void> stop() async {
    await flutterTts.stop();
  }
}
